CONNECT TO adp@
CREATE PROCEDURE processSchema(IN schemaName VARCHAR(10), IN ownerName VARCHAR(10))
LANGUAGE SQL
BEGIN
	DECLARE stmt VARCHAR(100);
	DECLARE a VARCHAR(10);
	
	SET schemaName = UCASE(schemaName);
	SET ownerName = UCASE(ownerName);
	
	SELECT schemaname INTO a
	FROM SYSCAT.SCHEMATA
	WHERE owner = ownerName;
	
	IF UCASE(a) = schemaName
	THEN
		SET stmt = 'DROP SCHEMA ' || schemaName || ' RESTRICT';
		PREPARE s1 FROM stmt;
		EXECUTE s1;
	END IF;
	SET stmt = 'CREATE SCHEMA ' || schemaName || ' AUTHORIZATION ' || ownerName;
	PREPARE s1 FROM stmt;
	EXECUTE s1;	

END@
call processSchema('ADP', 'ADP')@
DROP PROCEDURE processSchema@
CONNECT RESET@

